public class MyQueue {
    static class ListNode {
        public int val;
        public ListNode prev;
        public ListNode next;
        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode first=null;
    public ListNode last=null;
    public int usdSize=0;
    public void offer(int val){
        ListNode node=new ListNode(val);
        if(isEmpty()){
            first=last=node;
        }else{
            last.next=node;
            node.prev=last;
            last=last.next;
        }
        usdSize++;
    }
    public int poll() {
        if(isEmpty()){
            return -1;
        }else{
            usdSize--;
            int val=first.val;
            first=first.next;
            if(first!=null) {
                first.prev = null;
            }
            return val;
        }
    }
    public int peek() {
        if(isEmpty()){
            return -1;
        }else{
            int val=first.val;
            return val;
        }
    }
    public boolean isEmpty(){
        return usdSize==0;
    }
}
